angular.module('app').run(['$rootScope', 'userInfo', 'utils', '$state', 'product', '$interval', function($rootScope, userInfo, utils, $state, product, $interval) {
	userInfo.user_code = localStorage.user_code //用户user_code
	userInfo.user_type = localStorage.user_type //用户user_type
	userInfo.phone = localStorage.phone //用户phone
    userInfo.soloCode = localStorage.soloCode //用户phone
	/*判断是否app内打开*/
	$rootScope.isapp = false
	try {
		if(wv) {
			$rootScope.isapp = true
		}
	} catch(e) {

	}
	/*加载url*/
	$rootScope.sendUrl=function(item){
		window.location=item
	}
	
	
	/*切换路由返回顶部*/
	$rootScope.$on('$stateChangeSuccess', function(event, unfoundState, fromState, fromParams) {
		document.body.scrollTop = document.documentElement.scrollTop = 0;
	})

	/*购买弹窗开关变量*/
	$rootScope.isShow = false

	/*路由拦截*/
	$rootScope.$on("$stateChangeStart", function(event, tostate, toParams, formstate, formParams) {

		/*判断是否登录*/
		if(tostate.islogin) {
			if(!userInfo.user_code) {
				event.preventDefault()
				$state.go("register")
				return
			}
		}
		/*清空定时器*/
		angular.forEach(product.timers, function(value, index) {
			$interval.cancel(value)
		})
		product.timers = []

	})

}])